<template>
    <div>
        <Row>
            <i-col span="8" :class="{'hidden': Sketchpad.isFullScreen}">
                <div class="mb-2">
                    <span>{{sketchpadLabel}}：{{Sketchpad.name}}</span>
                </div>
                <!-- {{Sketchpad}} -->
                <Collapse class="mr-2 mb-2" accordion
                    v-for="(apiCard,$index) in ApiNav.data" 
                    :key="apiCard.oid" 
                    :value="apiCard.oid+''" 
                    :class="apiCard.indentClass" 
                    @on-change="v=>{loadApiCardTree(apiCard)}">
                    
                    <!-- 默认打开第一个API卡片 -->
                    <Panel :name="ApiNav.data[0].oid+''">
                        <!-- 卡片标题编辑 -->
                        <span v-show="!apiCard.editer.on" class="ml-1">{{apiCard.aliasName}}</span>
                        <Input clearable v-show="apiCard.editer.on" type="text" v-model="apiCard.aliasName" style="width:50%;"  />
                        
                        <!-- 卡片操作项 -->
                        <div style="float:right;">
                            <!-- 保存和编辑标题 -->
                            <Button icon="edit" class="unfocus" shape="circle" size="small" type="text" 
                                v-show="!apiCard.editer.on" 
                                @click.stop="apiCard.editer.on = true" >
                            </Button>
                            <Button icon="checkmark-round" class="ml-1 unfocus" shape="circle" size="small" type="text" 
                                :loading="apiCard.editer.loading"
                                 v-show="apiCard.editer.on" 
                                 @click.stop="updateCardTitle(apiCard,$index)">
                            </Button>
                            <!-- API下探 -->
                            <Button icon="merge" shape="circle" size="small" type="text"
                                @click.stop="clickAddCard(apiCard)">
                            </Button>
                            <!-- 搜索API内容，暂不实现 -->
                            <Button icon="search" shape="circle" size="small" type="text"
                                disabled v-if="apiCard.isBaseCard" @click.stop="searchCard">
                            </Button>
                            <!-- 删除API卡片 -->
                            <Button icon="trash-b" shape="circle" size="small" type="text"
                                v-if="!apiCard.isBaseCard" 
                                @click.stop="removeCard(apiCard)">
                            </Button>
                        </div>
                        <div slot="content">
                            <!-- {{apiCard}} -->
                            <!-- API数据卡片下的字典结构 -->
                            <!-- {{apiCard.dictTreeList}} -->
                            <v-jstree 
                                v-if="apiCard.dictTreeList"
                                v-show="apiCard.dictTreeList.length > 0" 
                                :data="apiCard.dictTreeList" 
                                @item-click="clickApiCardNode" />
                                
                            <small class="text-muted" v-show="apiCard.dictTreeList.length == 0">暂无数据</small>
                        </div>
                    </Panel>
                </Collapse>
            </i-col>
            <!-- {{Sketchpad.isFullScreen}}  :span="decideContentSpan"  span="14" -->
            <i-col :span="decideContentSpan">
                <!-- {{DecideContent.activeTab}} -->    
                <Tabs type="card" class="mr-2" 
                    v-model="DecideContent.activeTab" 
                    @on-click="switchDecideContent">
                    
                    <TabPane :label="choiseNodeLabel" icon="hammer" name="workspace">
                        <b-card no-body>
                            <b-card-header>
                                <!-- 当前判定节点名 -->
                                <strong 
                                    v-show="!DecideContent.NodeWorkspaceTab.nodeNameEditor.on"> 
                                    {{DecideContent.NodeWorkspaceTab.nodeName}}
                                </strong>
                                <Input clearable type="text" style="width:50%;"
                                    v-show="DecideContent.NodeWorkspaceTab.nodeNameEditor.on" 
                                    v-model="DecideContent.NodeWorkspaceTab.nodeName"/>
                                <!-- 开启编辑判定节点名 -->
                                <Button icon="checkmark-round" class="ml-1 unfocus" shape="circle" size="small" type="text" 
                                    v-show="DecideContent.NodeWorkspaceTab.nodeNameEditor.on" 
                                    @click="DecideContent.NodeWorkspaceTab.nodeNameEditor.send(updateNodeName)"
                                    :loading="DecideContent.NodeWorkspaceTab.nodeNameEditor.loading">
                                </Button>
                                <!-- 保存判定节点名 -->
                                <Button icon="edit" class="ml-1" shape="circle" size="small" type="text" 
                                    v-show="!DecideContent.NodeWorkspaceTab.nodeNameEditor.on" 
                                    @click="DecideContent.NodeWorkspaceTab.nodeNameEditor.switch()">
                                </Button>
                            </b-card-header>
                            <b-card-body style="padding-top: 5px;">
                                <!-- 数据源对象 -->
                                <div class="card-item mb-4">
                                    <div class="card-item-header">
                                        <span>已选择的数据对象：</span>
                                        <span class="fix-btn" v-show="DecideContent.NodeWorkspaceTab.choiseApi.changeApiLoading">
                                            <Spin>
                                                <Icon type="load-c" size=18 class="demo-spin-icon-load"></Icon>
                                            </Spin>
                                        </span>
                                    </div>
                                    <div class="tool-play mb-1" 
                                        v-if="DecideContent.NodeWorkspaceTab.choiseApi.fieldOid">
                                        {{DecideContent.NodeWorkspaceTab.choiseApi.apiPath}}
                                    </div>
                                    <div v-else>
                                        <small class="text-muted">(选择左侧任意节点)</small>
                                    </div>
                                    
                                    <span>已选择的数据对象的属性：</span>
                                    <div class="tool-play" v-if="DecideContent.NodeWorkspaceTab.choiseApi.fieldOid">
                                        {{DecideContent.NodeWorkspaceTab.choiseApi.fieldText}}
                                    </div>
                                    <div v-else>
                                        <small class="text-muted">(选择左侧任意节点)</small>
                                    </div>
                                </div>

                                <div class="card-item mb-4">
                                    <!-- <div>
                                    {{DecideContent.NodeWorkspaceTab.choiseTool}}
                                    </div> -->
                                    <span>判定工具：
                                        <small class="text-muted" v-if="DecideContent.NodeWorkspaceTab.choiseTool">
                                            {{DecideContent.NodeWorkspaceTab.choiseTool.name}}
                                        </small>
                                        <small class="text-muted" v-else>(选择右侧判定工具)</small>
                                    </span>
                                    <Row>
                                        <i-col span="24">
                                            <template v-if="DecideContent.NodeWorkspaceTab.choiseTool">
                                                <!-- 判定工具实例 -->
                                                <component ref="ToolComponent" class="mb-2"
                                                    v-bind:is="toolComponentList[DecideContent.NodeWorkspaceTab.choiseTool.code]" 
                                                    :val="DecideContent.NodeWorkspaceTab.choiseTool.determinationData">
                                                </component>
                                                <!-- {{DecideContent.NodeWorkspaceTab.choiseTool.determinationData}} -->
                                                <!-- 修改判定工具内容-保存按钮 -->
                                                <Button icon="checkmark-round" class="ml-1 unfocus" size="small" type="primary" shape="circle"
                                                    v-if="globalConst.DECIDE_TOOL_CONFIG[DecideContent.NodeWorkspaceTab.choiseTool.code] && globalConst.DECIDE_TOOL_CONFIG[DecideContent.NodeWorkspaceTab.choiseTool.code].hasDeterminationData"
                                                    :loading="DecideContent.NodeWorkspaceTab.choiseTool.changeApiLoading" 
                                                    @click="saveTool" title="保存">
                                                    保存
                                                </Button>
                                            </template>
                                        </i-col>
                                    </Row>
                                </div>
                                <div>
                                    <!-- 判定处理 -->
                                    <Tabs v-model="DecideContent.NodeWorkspaceTab.determinateWay">
                                        <TabPane icon="arrow-left-a" label="True" name="trueAction" class="tab-show">
                                            <!-- 判定方式:无动作/执行操作/链接子判定 -->
                                            <Row class="mb-2">
                                                <i-col span="24">
                                                    <RadioGroup type="button" 
                                                        v-model="DecideContent.NodeWorkspaceTab.determinateTrueAction.actionType" 
                                                        @on-change="switchDeterminateAction(true)">
                                                        
                                                        <Radio v-for="actionItem in bz_const.DETERMINATE_ACTIONS" :key="actionItem.value" :label="actionItem.value">{{actionItem.text}}</Radio>
                                                    </RadioGroup>
                                                </i-col>
                                            </Row>
                                            <!-- True的判定处理 -->
                                            <Row class="mb-2" 
                                                v-if="Sketchpad.type === 'scorecard'"
                                                v-show="DecideContent.NodeWorkspaceTab.determinateTrueAction.actionType === 'Action'">
                                                <i-col span="4">
                                                    <label style="line-height:32px;">分数调整值：</label>
                                                </i-col>
                                                <i-col span="5">
                                                    <InputNumber 
                                                        v-if="DecideContent.NodeWorkspaceTab.determinateTrueAction.actionType === 'Action'" 
                                                        v-model="DecideContent.NodeWorkspaceTab.determinateTrueAction.classData.scoreAdj" style="width:100%;"></InputNumber>
                                                    <Button 
                                                            icon="checkmark-round" 
                                                            class="ml-1 unfocus mt-2" 
                                                            size="small" 
                                                            type="primary"
                                                            shape="circle"
                                                            title="保存"
                                                            :loading="DecideContent.NodeWorkspaceTab.determinateTrueAction.changeActionLoading"
                                                            @click="saveDeterminateData">
                                                            保存
                                                            </Button>
                                                </i-col>
                                            </Row>
                                            <Row class="mb-2" 
                                                v-else
                                                v-show="DecideContent.NodeWorkspaceTab.determinateTrueAction.actionType === 'Action'">
                                                <Row class="mb-2">
                                                    <i-col span="4">
                                                        <label style="line-height:32px;">事件标题：</label>
                                                    </i-col>
                                                    <i-col span="6">
                                                        <i-input 
                                                            type="textarea" :rows="4" style="100%"
                                                            v-if="DecideContent.NodeWorkspaceTab.determinateTrueAction.actionType === 'Action'"
                                                            v-model="DecideContent.NodeWorkspaceTab.determinateTrueAction.classData.eventSubject">
                                                        </i-input>
                                                    </i-col>
                                                </Row>
                                                <Row>
                                                    <i-col span="4">
                                                        <label style="line-height:32px;">事件级别：</label>
                                                    </i-col>
                                                    <i-col span="6">
                                                        <b-select 
                                                            v-model="DecideContent.NodeWorkspaceTab.determinateTrueAction.classData.warningLevel" 
                                                            :options="alertLevelList" />
                                                    </i-col>
                                                </Row>
                                                <Row>
                                                    <Button 
                                                        icon="checkmark-round" 
                                                        class="ml-1 unfocus mt-2" 
                                                        size="small" 
                                                        type="primary"
                                                        shape="circle"
                                                        title="保存"
                                                        :loading="DecideContent.NodeWorkspaceTab.determinateTrueAction.changeActionLoading"
                                                        @click="saveDeterminateData">
                                                        保存
                                                        </Button>
                                                </Row>
                                            </Row>
                                        </TabPane>
                                        <TabPane icon="arrow-right-a" label="False" name="falseAction" class="tab-show">
                                            <Row>
                                                <i-col span="24">
                                                    <RadioGroup 
                                                            v-model="DecideContent.NodeWorkspaceTab.determinateFalseAction.actionType" 
                                                            type="button"
                                                            @on-change="switchDeterminateAction(false)">
                                                        <Radio v-for="actionItem in bz_const.DETERMINATE_ACTIONS" :key="actionItem.value" :label="actionItem.value">{{actionItem.text}}</Radio>
                                                    </RadioGroup>
                                                </i-col>
                                            </Row>

                                            <Row class="mt-2 mb-4" 
                                                v-if="Sketchpad.type === 'scorecard'"
                                                v-show="DecideContent.NodeWorkspaceTab.determinateFalseAction.actionType === 'Action'">
                                                <i-col span="4">
                                                    <label style="line-height:32px;">分数调整值：</label>
                                                </i-col>
                                                <i-col span="4">
                                                    <InputNumber 
                                                        v-if="DecideContent.NodeWorkspaceTab.determinateFalseAction.actionType === 'Action'"
                                                        v-model="DecideContent.NodeWorkspaceTab.determinateFalseAction.classData.scoreAdj" style="width:100%;"></InputNumber>
                                                    <Button 
                                                            icon="checkmark-round" 
                                                            class="ml-1 unfocus mt-2" 
                                                            size="small" 
                                                            type="primary"
                                                            shape="circle"
                                                            title="保存"
                                                            :loading="DecideContent.NodeWorkspaceTab.determinateFalseAction.changeActionLoading"
                                                            @click="saveDeterminateData">
                                                            保存
                                                            </Button>
                                                </i-col>
                                            </Row>
                                            <Row class="mb-2" 
                                                v-else
                                                v-show="DecideContent.NodeWorkspaceTab.determinateFalseAction.actionType === 'Action'">
                                                <Row class="mb-2">
                                                    <!-- {{DecideContent.NodeWorkspaceTab.determinateFalseAction.classData}} -->
                                                    <i-col span="4">
                                                        <label style="line-height:32px;">事件标题：</label>
                                                    </i-col>
                                                    <i-col span="6">
                                                        <Input 
                                                            type="textarea" :rows="4" style="100%"
                                                            v-model="DecideContent.NodeWorkspaceTab.determinateFalseAction.classData.eventSubject">
                                                        </Input>
                                                    </i-col>
                                                </Row>
                                                <Row>
                                                    <i-col span="4">
                                                        <label style="line-height:32px;">事件级别：</label>
                                                    </i-col>
                                                    <i-col span="6">
                                                        <b-select 
                                                            v-model="DecideContent.NodeWorkspaceTab.determinateFalseAction.classData.warningLevel" 
                                                            :options="alertLevelList" />
                                                    </i-col>
                                                </Row>
                                                <Row>
                                                    <Button 
                                                        icon="checkmark-round" 
                                                        class="ml-1 unfocus mt-2" 
                                                        size="small" 
                                                        type="primary"
                                                        shape="circle"
                                                        title="保存"
                                                        :loading="DecideContent.NodeWorkspaceTab.determinateTrueAction.changeActionLoading"
                                                        @click="saveDeterminateData">
                                                        保存
                                                        </Button>
                                                </Row>
                                            </Row>
                                        </TabPane>
                                    </Tabs>
                                    <!-- 链接子判定面板 -->
                                    <!-- v-show="(showTrueShortcut && decideWorkspace.trueAction.actionType === 'LinkNode') || (showFalseShortcut && decideWorkspace.falseAction.actionType === 'LinkNode')" -->
                                    <div class="link-node" >
                                        <div class="float-left" 
                                            v-if="DecideContent.NodeWorkspaceTab.determinateTrueAction.actionType === 'LinkNode'">
                                            <a href="javascript:void(0);" class="badge badge-info badge-pill" 
                                                @click="reloadWorkspaceByLink(true)">
                                                <Icon type="arrow-left-c" class="mr-2"></Icon>True子判定快捷链接
                                            </a>
                                        </div>

                                        <div class="float-right" 
                                            v-if="DecideContent.NodeWorkspaceTab.determinateFalseAction.actionType === 'LinkNode'">
                                            <a href="javascript:void(0);" class="badge badge-info badge-pill" 
                                                @click="reloadWorkspaceByLink(false)">
                                                <Icon type="arrow-right-c" class="mr-2"></Icon>False子判定快捷链接
                                            </a>
                                        </div>
                                    </div>
                                </div>
                            </b-card-body>
                        </b-card>
                    </TabPane>
                    <TabPane label="节点视图" icon="android-map" name="nodeMap">
                        <div class="nodeMap" id="myDiagramDiv"></div>
                    </TabPane>
                </Tabs>

            </i-col>
            <!-- 判定工具 -->
            <i-col span="2"  :class="{'hidden': Sketchpad.isFullScreen}">
                <b-card header="工具" header-tag="h6" class="mb-1 tool-item-container text-center">
                    <sky-tool-item v-for="tool in ToolNav.source" 
                     v-if="tool.show" 
                    :oid="tool.oid"
                    :key="tool.code" 
                    :code="tool.code" 
                    :label="tool.name" 
                    :enable="tool.enable" 
                    :desc="tool.description"
                    :img="globalConst.DECIDE_TOOL_CONFIG[tool.code].icon">
                    </sky-tool-item>
                    <small class="text-muted" v-show="ToolNav.source.length == 0">暂无数据</small>
                </b-card>
            </i-col>
        </Row>
        <!-- 节点视图 -->
        <Modal 
            ref="AddApiCardModal"
            v-model="AddApiCardModal.show" 
            title="选择下探数据接口" 
            :mask-closable="false" :loading=true
            @on-ok="addCard">
            <Table stripe border
                :columns="AddApiCardModal.table.columns"
                :data="AddApiCardModal.table.data"
                @on-select="(select,row) => {
                    let vm = this;
                    AddApiCardModal.selectFn.call(vm,select,row)
                }"
                @on-select-all="(selection) => {
                    let vm = this;
                    AddApiCardModal.selectAllFn.call(vm,selection)
                }"
                ></Table>
        </Modal>
    </div>
</template>

<style src="@/vendor/libs/vue-data-tables/vue-data-tables.scss" lang="scss"></style>
<style src="@/vendor/libs/sweet-modal-vue/sweet-modal-vue.scss" lang="scss"></style>
<style src="@/vendor/libs/vue-jstree/vue-jstree.scss" lang="scss"></style>
<style scoped>
@keyframes ani-demo-spin {
    from { transform: rotate(0deg);}
    50%  { transform: rotate(180deg);}
    to   { transform: rotate(360deg);}
}

.nodeMap {
    height: 450px;
    width: 100%;
    margin: 0 auto;
    border: 1px solid #ccc;
    background-color: white;
}

.tool-item-container > div.card-body {
    padding: 4px;
}

.tool-play {
    border: 1px dashed gray;
    padding: 4px;
    text-align: left;
    background-color: whitesmoke;
}

div.ivu-collapse.ml-0 {
    border: 1px dashed #666;
}

.unfocus.ivu-btn:focus{
    box-shadow: none !important; 
}

.fix-btn{
    position: absolute;
    right: 4px;
    top: 4px;
}

.card-item-header{
    line-height:38px;
    height:38px;
    position:relative;
}

.link-node{
    vertical-align: middle;
    min-height: 30px;
    line-height: 30px;
}

.hidden{
    display: none;
}
</style>

<script>
import Vue from 'vue';
import VJstree from 'vue-jstree';
import go from 'gojs';
import ToolDengYu from '@/commComponents/toolComponents/Dengyu';
import ToolDateZaoYu from '@/commComponents/toolComponents/DateZaoYu';
import ToolStringContains from '@/commComponents/toolComponents/StringContains';
import ToolDaYu from '@/commComponents/toolComponents/DaYu';
import ScoreAction from '@/commComponents/ScoreAction';
import IndicatorShortcut from '@/commComponents/IndicatorShortcut';
import ToolOwnerchangecount from '@/commComponents/toolComponents/ToolOwnerchangecount';
import GLOBAL_CONST from '@/const';
// import CONST from '@/components/riskTool/scorecard/const.js'
import '@/assets/icons';

// 文本编辑器原型对象
var TextEdit = function() {
  return {
    on: false,
    loading: false,
    switch: function() {
      this.on = !this.on
        },
    send: function(sendFn) {
      const self = this
            self.loading = true
            //发送请求
            sendFn().then(function(res) {
        self.switch()
                self.loading = false
            }, function(e) {
        self.loading = false
            })
        }
  }
}

export default {
  name: 'ui-treeview',
  metaInfo: {
    title: '智能风控平台 - 画板'
  },
  components: {
    VJstree,
    ToolDengYu,
    ToolDateZaoYu,
    ToolStringContains,
    ToolDaYu,
    'score-action': ScoreAction,
    'indicator-shortcut': IndicatorShortcut
  },
  data: () => ({
    // 全局常量
    globalConst: GLOBAL_CONST,
    // 页面常量
    bz_const: {
      MAP_COLOR: {
        blue: '#2b85e4',
        pink: '#e780a3',
        gray: '#bbbec4'
      },
      DETERMINATE_ACTIONS: [
        {
          text: '无动作',
          value: 'NoAction'
        },
        {
          text: '执行操作',
          value: 'Action'
        },
        {
          text: '链接子判定',
          value: 'LinkNode'
        }
      ]
    },
    // 判定工具列表
    toolComponentList: {
      gt: ToolDaYu, // 大于
      lt: null, // 小于
      eq: ToolDengYu, // 等于
      neq: null, // 不等于
      contains: ToolStringContains, // 包含
      between: null, // 区间
      monthBefore: ToolDateZaoYu, // 日期早于
      ownerchangecount: ToolOwnerchangecount // 法人变更次数大于
    },
    // 事件级别
    alertLevelList: [
      {
        text: '高',
        value: 1
      },
      {
        text: '中',
        value: 2
      },
      {
        text: '低',
        value: 3
      }
    ],
    Sketchpad: {
      id: 0, 	// 画板id
      nmae: '',	// 画板名称
      type: '',	// 画板类型
      isFullScreen: false // 是否全屏操作
    },
    ApiNav: {
      source: [],	// 原始数据
      // 列表数据
      data: [
        {
          oid: '',	// 卡片id
          aliasName: '',	// 卡片标题，即源数据中的aliasName
          editer: TextEdit(),	// 标题编辑器
          isBaseCard: true,	// 是否为根卡片
          baseClass: '', // 根卡片Class
          indentClass: '',	// 卡片缩进层级
          dictTreeList: []	// API卡片的字典数据
        }
      ]
    },
    DecideContent: {
      // 主内容区当前的标签页(nodeMap/workspace)
      activeTab: 'nodeMap',
      // 工作区Tab
      NodeWorkspaceTab: {
        nodeName: '',	// 判定节点名称
        nodeNameEditor: TextEdit(),	// 判定节点编辑器
        // 选中的下探数据对象
        choiseApi: {
          fieldOid: 0,
          fieldName: 'legalPerson',
          fieldType: 'String',
          fieldText: '',
          apiOid: 0,
          apiPath: '',
          pathName: '',
          changeApiLoading: false // 修改下探数据的加载状态
        },
        // 选中的判定工具
        choiseTool: {
          oid: null,
          name: '',	// 判定工具名称
          code: '',	// 判定工具编码
          determinationData: '',	// 判定工具内容
          changeToolLoading: false // 修改判定工具的加载状态
        },
        // 判定处理
        determinateWay: 'trueAction',	// 判定结果(真/假)
        // 判定为真的处理方式
        determinateTrueAction: {
          oid: 0,
          actionType: 'NoAction',
          classData: { scoreAdj: 0 },	// 执行操作的数据内容
          childNode: null, // 子链数据
          changeActionLoading: false // 修改判定动作的加载状态
        },
        // 判定为假的处理方式
        determinateFalseAction: {
          oid: 0,
          actionType: 'NoAction',
          classData: { scoreAdj: 0 },	// 执行操作的数据内容
          childNode: null, // 子链数据
          changeActionLoading: false // 修改判定动作的加载状态
        }
      },
      // 节点视图
      NodeMapTab: {
        diagram: null, //
        source: [],	// 源数据
        choiseNode: null	// 当前选中的节点
      }
    },
    ToolNav: {
      source: []
    },
    AddApiCardModal: {
      sourceOid: 0, // 下探来源的节点
      show: false,	// 是否显示
      selectionMap: {},	// 选中的数据集合
      table: {
        // 多选表格的列配置
        columns: [
          {
            type: 'selection',
            width: 60,
            align: 'center'
          },
          {
            title: '接口别名',
            key: 'aliasName'
          }
        ],
        // 多选表格的数据
        data: []
      },
      // 清空选择
      clearFn: function() {
        this.AddApiCardModal.selectionMap = {}
            },
      // 选中表格数据时执行
      selectFn: function(selection, row) {
        this.AddApiCardModal.selectionMap[row.oid] = row
            },
      // 全选表格数据时执行
      selectAllFn: function(selection) {
        const self = this
                if (selection) {
          selection.forEach(function(item) {
            self.AddApiCardModal.selectionMap[item.oid] = item
                    })
                }
      },
      // 点击保存执行
      confirmFn: function() {

      }
    }
  }),
  // 实时监听变化
  computed: {
    decideContentSpan: function() {
      // console.log(this.Sketchpad.isFullScreen);
      if (this.Sketchpad.isFullScreen) {
        return 24
            }else {
        return 14
            }
    },
    sketchpadLabel: function() {
      return this.Sketchpad.type === 'scorecard' ? '打分卡名称' : '预警规则名称'
        },
    choiseNodeLabel: function() {
      return this.DecideContent.NodeMapTab.choiseNode ? this.DecideContent.NodeMapTab.choiseNode.nodeName + '编辑' : '节点编辑'
        }
    // :class="{'hidden': !Sketchpad.isFullScreen}"
    // showTrueShortcut: function() {
    //     return this.decideWorkspace.trueAction.actionType === "LinkNode";
    // },
    // showFalseShortcut: function() {
    //     return this.decideWorkspace.falseAction.actionType === "LinkNode";
    // }
  },
  methods: {
    // 修改卡片标题
    updateCardTitle(card, $index) {
      const self = this

            card.editer.on = true
            // let newCard = card;

            self.$http.put(
        '/app/v1/sketchpads/diggingCards/' + card.oid, card.aliasName
      )
        .then(function(res) {
          card.editer.on = false

                    if (res.code === 0) {
            self.$Notice.success({
              title: '系统提示',
              desc: res.desc
            })
                    } else{
            self.$Notice.error({
              title: '系统提示',
              desc: res.desc
            })
                    }
        }, function(res) {
          self.$Notice.error({
            title: '系统提示',
            desc: res.desc
          })
                })

            // console.log(apiCard,$index);
        },
    // 新增卡片
    addCard() {
      const self = this

            let addApiCardModal = self.AddApiCardModal
            // 获取选中的数据源oid列表
            let addApiOidList = Object.keys(addApiCardModal.selectionMap)
            let url = '/app/v1/sketchpads/diggingCards/' + addApiCardModal.sourceOid + '/diggingCards';

      // 发送请求
      self.$http
        .post(url, addApiOidList)
        .then(function(res) {
          if (res.code === 0) {
            self.$refs.AddApiCardModal.close()

                        self.$Notice.success({
              title: '系统提示',
              desc: res.desc
            })

                        self.loadApiCardList()
                    } else{
            self.$Notice.error({
              title: '系统提示',
              desc: res.desc
            })
                    }
        })
        },
    // 删除卡片
    removeCard(apiCard) {
      const self = this
            let url = '/app/v1/sketchpads/diggingCards/' + apiCard.oid

            self.$Modal.confirm({
        title: '系统提示',
        content: '<p>确认删除“' + apiCard.aliasName + '”？</p>',
        onOk: () => {
          self.$http.delete(url).then(function(resp) {
            if (resp.code === 0) {
              // 删除成功提示
              self.$Message.success('删除成功!')
                            // 左侧API数据列表刷新
                            self.loadApiCardList()     
                        }else {
              self.$Message.error('删除失败！')
                        }
          })
                },
        onCancel: () => {
          self.$Message.info('取消删除')
                }
      })  
        },
    // 搜索卡片内容,暂不实现
    // searchCard(){},
    // 加载左侧API数据列表
    loadApiCardList() {
      const self = this
            // 清空数据
            self.ApiNav.source = []
            self.ApiNav.data = []
                // 请求URL
            let url = '/app/v1/sketchpads/' + self.Sketchpad.id + '/apiMasterRelation';
      // 发送请求
      self.$http.get(url).then(res => {
        if (res.code === 0) {
          // 赋值
          self.ApiNav.source = res.data
                        // 解析
                        self.parseApiNavSource(res.data)
                    }else {
          self.$Message.error('左侧API数据列表加载失败!')
        }
      })		
        },
    clickAddCard(apiCard) {
      const self = this
            // console.log('clickAddCard',apiCard);
            // 下探来源的节点
            self.AddApiCardModal.sourceOid = apiCard.oid
            // 清空选中的情况
            self.AddApiCardModal.selectionMap = []
            // 显示面板
            self.AddApiCardModal.show = true
            // 加载数据
            self.loadCardDictTree(apiCard.apiMasterOid).then(function(resp) {
        // 响应结果赋值
        self.AddApiCardModal.table.data = resp.data ? resp.data : []
            })
        },
    // 载入API卡片下的字典数据
    loadCardDictTree(apiMasterOid) {
      const self = this
            let url = '/app/v1/apis/' + apiMasterOid + '/relations?pageSize=' + 1000
        
            return new Promise(function(resolve, reject) {
        self.$http.get(url).then(res => {
          if (res.code === 0) {
            resolve(res)
                        }else {
            reject(res)
                        }
        })
            })
        },
    // 左侧卡片列表源数据解析
    parseApiNavSource(dataList) {
      const self = this
            dataList.forEach(function(item, key, arr) {
        // 计算缩进位数
        const indentNum = (item.level >= 3) ? 5 : item.level * 2
                // 组织卡片数据对象
                let apiCard = {
          // 卡片oid
          oid: item.oid,
          aliasName: item.aliasName,
          // 卡片名称编辑器
          editer: new TextEdit(),
          // 卡片缩进Class
          indentClass: 'ml-' + indentNum,
          // 是否为根卡片
          isBaseCard: item.parentOid === 0,
          // 根卡片Class
          baseClass:
                        item.parentOid === 0
                          ? 'border-secondary border-dashed'
                          : '',
          // API卡片的字典数据
          dictTreeList: [],
          // 数据源id
          apiMasterOid: item.apiMasterOid
        }

                // console.log(apiCard);
                
                // 预先加载主体的数据
                if (apiCard.isBaseCard) {
          self.loadApiCardTree(apiCard)
                }

        // 将解析结果放入数据
        self.ApiNav.data.push(apiCard)
                
                // 检测如果还有子级卡片，则重复执行当前方法
                if (item.childList) {
          self.parseApiNavSource(item.childList)
                }
      })
            // console.log(self.ApiNav.data);
        },
    // 加载数据源卡片下的数据
    loadApiCardTree(apiCard) {
      let self = this,
        oid = apiCard.apiMasterOid

            // console.log('loadApiCardTree come in',apiCard);
            let url = '/app/v1/sketchpads/apiRelations/' + apiCard.oid + '/resultDict';
      // console.log('loadApiCardTree come in',apiCard.aliasName,apiCard.oid);
      self.$http
        .get(url)
        .then(function(res) {
          // 遍历数组，手动set到数组中，否则Vue不会加入绑定监听
          const apiCardList = self.ApiNav.data
                    let respTreeData = res.data
                    
                    if (res.code === 0) {
            for (let i = 0; i < apiCardList.length; i++) {
              const targetApiCard = apiCardList[i]
                            // console.log(targetApiCard.oid,apiCard.oid);
                            if (targetApiCard.oid === apiCard.oid) {
                // console.log(respTreeData);
                targetApiCard.dictTreeList = respTreeData
                                Vue.set(self.ApiNav.data, i, targetApiCard)
                                // return;
                            }
            }
          } else{
            self.$Notice.error({
              title: '系统提示',
              desc: res.desc
            })
          }
          // console.log(self.ApiNav.data);
        })
                
        },
    // 点击选择API数据源，默认会传递jsTree组件中的node数据
    clickApiCardNode(jsTreeNode) {
      let self = this,
        node = jsTreeNode.model, // 当前选中的节点
        choiseNodeOid = self.DecideContent.NodeMapTab.choiseNode.oid
            
            // console.log(node);
            // console.log(self.arge);
            self.$Modal.confirm({
        title: '系统提示',
        content: `
                    <strong>${node.fieldLabel}</strong>
                    <p class="text-muted small">描述：${node.description ? node.description:'暂无'}</p>
                    <strong>确定切换？</strong>`,
        onOk: () => {
          // 每次点击数据字典时，自动切换面板
          self.DecideContent.activeTab = 'wrokspace';

          // 赋值当前选中的数据
          self.DecideContent.NodeWorkspaceTab.choiseApi = {
            fieldOid: node.oid,
            fieldName: node.fieldName,
            fieldType: node.fieldType,
            fieldText: node.text,
            apiOid: node.sketchpadApiMasterRelationOid,
            apiPath: node.apiPath,
            pathName: node.pathName,
            changeApiLoading: true
          }

                    // 发请求
                    self.saveApi(choiseNodeOid, {
            apiResultDictOid: node.oid,
            sketchpadApiMasterRelationOid: node.sketchpadApiMasterRelationOid
          }).then(function(res) {
            // 修改加载状态
            self.DecideContent.NodeWorkspaceTab.choiseApi.changeApiLoading = false
                        // 重新加载右侧工具类
                        self.loadToolList()

                        // 弹出提示
                        self.$Notice.success({
              title: '系统提示',
              desc: res.desc
            })
                        
                    })
                },
        onCancel: () => {
          self.$Message.info('取消切换')
                }
      }) 
        },
    // 加载主内容区数据详情
    loadDecideContentDetail() {
      const self = this
            let url = '/app/v1/sketchpads/' + self.Sketchpad.id + '/nodes/' + self.DecideContent.NodeMapTab.choiseNode.oid
            return new Promise(function(resolve, reject) {
        self.$http
          .get(url)
          .then(function(res) {
            if (res.code === 0) {
              resolve(res)
                        } else{
              reject(res)
                        }
          })
            })
        },
    // 改变API数据源
    saveApi(choiseNodeOid, param) {
      const self = this
            let url = '/app/v1/sketchpads/detemineNodes/' + choiseNodeOid
            return new Promise(function(resolve, reject) {
        // 发送请求
        self.$http
          .patch(url, param)
          .then(function(res) {
            if (res.code === 0) {
              resolve(res)
                        }else {
              reject(res)
                        }
          })
            })
    },
    // 切换主内容区执行函数
    switchDecideContent(node) {
      let self = this,
        choiseNodeOid = '',
        // 切换触发：默认Tab切换，根据NodeMap切换
        switchForm = (node && node.data) ? 'viewMap' : 'default'
            
            if (self.DecideContent.activeTab === 'nodeMap') {
        // 重新绘制NodeMap
        self.loadNodeMap().then(function(res) {
          if (res.code === 0) {
            self.DecideContent.NodeMapTab.source = res.data
                        self.DecideContent.NodeMapTab.choiseNode = res.data[0]
                        self.buildNodeMap()
                    } else{
            self.$Notice.error({
              title: '系统提示',
              desc: res.desc
            })
                    }
        })
                // 页面占屏调整
                self.Sketchpad.isFullScreen = true
            }else {
        // 页面占屏调整
        self.Sketchpad.isFullScreen = false
                // 数据重载
                self.loadDecideContentDetail()
          .then(function(res) {
            self.assignmentDecideContent(res.data)
                    })
            }
    },
    // 修改判定节点名
    updateNodeName() {
      const self = this
            let url = '/app/v1/sketchpads/detemineNodes/' + self.DecideContent.NodeMapTab.choiseNode.oid
            let param = {
        nodeName: self.DecideContent.NodeWorkspaceTab.nodeName
      }

            if (self.DecideContent.NodeMapTab.choiseNode) {
        self.DecideContent.NodeMapTab.choiseNode.nodeName = self.DecideContent.NodeWorkspaceTab.nodeName
            }

      return new Promise(function(resolve, reject) {
        self.$http
          .patch(url, param)
          .then(function(res) {
            self.$Notice.success({
              title: '系统提示',
              desc: res.desc
            })
                        resolve(res)
                    }, function(res) {
            reject(res)
                    })
            })
        },
    // 加载NodeMap(节点地图)数据
    loadNodeMap() {
      const self = this
            let url = '/app/v1/sketchpads/' + self.Sketchpad.id + '/determineNodeRelation';

      // 发送请求
      return new Promise(function(resolve, reject) {
        self.$http
          .get(url)
          .then(function(res) {
            if (res.code === 0) {
              resolve(res)
                        } else{
              reject(res)
                        }
          })
            })
    },
    // 构建并绘画NodeMap的组件
    buildNodeMap() {
      const self = this
            
            // 思维导图相关变量
            let $ = go.GraphObject.make
            let myDiagram = self.DecideContent.NodeMapTab.diagram

      if (myDiagram) {
        myDiagram.model = new go.TreeModel(self.DecideContent.NodeMapTab.source)
            } else {
        myDiagram = $(
          go.Diagram,
          'myDiagramDiv', // must be the ID or reference to div
          {
            'toolManager.hoverDelay': 100, // 100 milliseconds instead of the default 850
            allowCopy: false,
            // create a TreeLayout for the family tree
            layout: $(go.TreeLayout, {
              angle: 90,
              nodeSpacing: 10,
              layerSpacing: 40,
              layerStyle: go.TreeLayout.LayerUniform
            })
          }
        )

                // Set up a Part as a legend, and place it directly on the diagram
                myDiagram.add(
          $(go.Part, 'Table', {
            position: new go.Point(-200, -20),
            selectable: false
          })
        )

                // get tooltip text from the object's data
                function tooltipTextConverter(person) {
          var str = '';
          str += 'Born: ' + person.birthYear
                    if (person.deathYear !== undefined)
            {str += "\nDied: " + person.deathYear;}
          if (person.reign !== undefined)
            {str += "\nReign: " + person.reign;}
          return str
                }

        // define tooltips for nodes
        var tooltiptemplate = $(
          go.Adornment,
          'Auto',
          $(go.Shape, 'Rectangle', {
            fill: 'whitesmoke',
            stroke: 'black'
          }),
          $(
            go.TextBlock,
            {
              font: 'bold 8pt Helvetica, bold Arial, sans-serif',
              wrap: go.TextBlock.WrapFit,
              margin: 5
            },
            new go.Binding('text', '', tooltipTextConverter)
          )
        )

                // define Converters to be used for Bindings
                function genderBrushConverter(actionType) {
          if (actionType === 'LinkNode') return self.bz_const.MAP_COLOR.blue
                    if (actionType === 'NoAction') return self.bz_const.MAP_COLOR.gray
                    if (actionType === 'Action') return self.bz_const.MAP_COLOR.pink
                    return 'orange';
        }

        // replace the default Node template in the nodeTemplateMap
        myDiagram.nodeTemplate = $(
          go.Node,
          'Auto',
          {
            deletable: false,
            toolTip: tooltiptemplate,
            selectionChanged: self.clickNodeMap
          },

          new go.Binding('text', 'name'),
          $(
            go.Shape,
            'Rectangle',
            {
              fill: 'lightgray',
              stroke: null,
              strokeWidth: 0,
              stretch: go.GraphObject.Fill,
              alignment: go.Spot.Center
            },
            new go.Binding('fill', 'actionType', genderBrushConverter)
          ),
          $(
            go.TextBlock,
            {
              font: '700 12px Droid Serif, sans-serif',
              textAlign: 'center',
              margin: 10,
              maxSize: new go.Size(80, NaN)
            },
            new go.Binding('text', 'name')
          )
        )

                // define the Link template
                myDiagram.linkTemplate = $(
          go.Link, // the whole link panel
          { routing: go.Link.Orthogonal, corner: 5, selectable: false },
          $(go.Shape, { strokeWidth: 3, stroke: '#424242' })
        ) 

                // the gray link shape
                // create the model for the family tree
                myDiagram.model = new go.TreeModel(self.DecideContent.NodeMapTab.source)
                self.DecideContent.NodeMapTab.diagram = myDiagram
            }
    },

    // 点击NodeMap后重新加载工作区
    clickNodeMap(node) {
      const self = this
            self.$Modal.confirm({
        title: '系统提示',
        content: '<p>确定切换成判定节点“' + node.data.name + '”？</p>',
        onOk: () => {
          // this.DecideContent.NodeMapTab.choiseNode = evtData.data;
          // this.switchDecideContent(evtData.data);

          this.DecideContent.NodeMapTab.choiseNode = node.data
                    // 切换成工作区
                    self.DecideContent.activeTab = 'workspace'
                    // 切换
                    self.switchDecideContent()
                },
        onCancel: () => {
          self.$Message.info('取消切换')
                }
      }) 
        },
    // 切换判定方式:无动作/执行操作/链接子判定
    switchDeterminateAction(determinateWay) {
      const self = this

            // 判定
            let workspace = self.DecideContent.NodeWorkspaceTab
            // 判定结果
            //let determinateWay = workspace.determinateWay === 'trueAction' ? true : false;
            // 判定结果的节点oid
            let determinateWayOid = determinateWay ? workspace.determinateTrueAction.oid : workspace.determinateFalseAction.oid
            // 判定方式
            let choiseAction = determinateWay ? workspace.determinateTrueAction.actionType : workspace.determinateFalseAction.actionType

            // 请求参数
            let url = '/app/v1/sketchpads/detemineNodeActions/' + determinateWayOid + '/actionSwitch';
      const param = {
        actionType: choiseAction
      }

            // 发送请求
            self.$http
        .patch(url, param)
        .then(function(res) {
          if (res.code === 0) {
            // 提示信息
            self.$Notice.success({
              title: '系统提示',
              desc: res.desc
            })

            // 如果切换到链接子节点，则根据情况赋值
            if (choiseAction === 'LinkNode') {
              // if(determinateWay){
              //     workspace.determinateTrueAction = res.data;
              // }else{
              //     workspace.determinateFalseAction = res.data;
              // }
            }
          } else {
            self.$Notice.error({
              title: '系统提示',
              desc: res.desc
            })
          }
        })	
        },
    // 保存判定处理
    saveDeterminateData() {
      const self = this
            // console.log('saveDeterminateData come in');
            // 判定
            let workspace = self.DecideContent.NodeWorkspaceTab
            // 判定结果
            let determinateWay = workspace.determinateWay === 'trueAction';
      // 判定结果对象
      const determinateWayObj = determinateWay ? workspace.determinateTrueAction : workspace.determinateFalseAction
            // console.log('saveDeterminateData',determinateWayObj);
            // 判定结果的节点oid
            let determinateWayOid = determinateWayObj.oid
            // 判定处理数据
            let choiseClassData = determinateWayObj.classData

            // 请求参数
            let url = '/app/v1/sketchpads/detemineNodeActions/' + determinateWayOid
            let param = {
        'actionClass': self.Sketchpad.type === 'scorecard' ? 'ScoreAdj' : 'Event',
        'classData': JSON.stringify(choiseClassData)
      }

      // 设置按钮加载状态
      determinateWayObj.changeActionLoading = true

            // 发送请求
            self.$http
        .patch(url, param)
        .then(function(res) {
          determinateWayObj.changeActionLoading = false
                    if (res.code === 0) {
            self.$Notice.success({
              title: '系统提示',
              desc: res.desc
            })
                    }else {
            self.$Notice.success({
              title: '系统提示',
              desc: res.desc
            })
                    }
        })
        },
    // 根据子链重新载入工作区面板数据
    reloadWorkspaceByLink(actionWay) {
      const self = this
            let workspace = self.DecideContent.NodeWorkspaceTab

            self.$Modal.confirm({
        title: '系统提示',
        content: `<strong>确定切换到子判定节点？</strong>`,
        onOk: () => {
          // 根据true/fasle，获取判定对象
          const childNode = actionWay ? workspace.determinateTrueAction.childNode : workspace.determinateFalseAction.childNode

                    if (childNode) {
            self.DecideContent.NodeMapTab.choiseNode.oid = childNode.oid
                        // this.assignmentDecideContent(choiseNodeRes);
                        this.switchDecideContent()
                    }
        },
        onCancel: () => {
          self.$Message.info('取消切换')
                }
      }) 
        },
    // 主内容区判定赋值
    assignmentDecideContent(respData) {
      const self = this
            // console.log(respData);

            // true处理的相关数据变量
            let trueActionClassData = '', trueActionType = ''
            // false处理的相关数据变量
            let falseActionClassData = '', faleActionType = ''
            
            // 如果响应中包含true判定
            if (respData.leftNodeAction) {
        // 对true判定的处理内容进行赋值
        if (respData.leftNodeAction.classData) {
          trueActionClassData = JSON.parse(respData.leftNodeAction.classData)
                }
        // 对true判定的判定方式进行赋值
        if (respData.leftNodeAction.actionType) {
          trueActionType = respData.leftNodeAction.actionType
                }
      }

      // 如果想要中包含false判定
      if (respData.rightNodeAction) {
        // 对false判定的处理内容进行赋值
        if (respData.rightNodeAction.classData) {
          falseActionClassData = JSON.parse(respData.rightNodeAction.classData)
                }
        // 对false判定的判定方式进行赋值
        if (respData.rightNodeAction.actionType) {
          faleActionType = respData.rightNodeAction.actionType
                }
      }

      // 选中左侧节点的真实api路径
      let sketchpadApiPath = null
            if (respData.sketchpadApiMasterRelation) {
        sketchpadApiPath = respData.sketchpadApiMasterRelation.apiPath
            }

      // 重新赋值
      self.DecideContent.activeTab = 'workspace'
            self.DecideContent.NodeWorkspaceTab.nodeName = respData.nodeName
            
            // respData.apiResultDict
            // sketchpadApiPath 左側api路径
            let apiResultDict = respData.apiResultDict
            self.DecideContent.NodeWorkspaceTab.choiseApi = {
        fieldOid: apiResultDict ? apiResultDict.oid : null,
        fieldName: apiResultDict ? apiResultDict.fieldName : null,
        fieldType: apiResultDict ? apiResultDict.fieldType : null,
        fieldText: apiResultDict ? apiResultDict.text : null,
        apiOid: apiResultDict ? apiResultDict.sketchpadApiMasterRelationOid : null,
        apiPath: sketchpadApiPath,
        pathName: apiResultDict ? apiResultDict.pathName : null,
        changeApiLoading: false
      }

      const determinationTool = respData.determinationTool
            if (determinationTool) {
        self.DecideContent.NodeWorkspaceTab.choiseTool = {
          name: determinationTool.name,	// 判定工具名称
          code: determinationTool.code,	// 判定工具编码
          oid: determinationTool.oid,
          determinationData: respData.determinationData,	// 判定工具内容
          changeToolLoading: false // 修改判定工具的加载状态
        }
      }

      self.DecideContent.NodeWorkspaceTab.determinateTrueAction = {
        oid: respData.leftNodeAction.oid,
        actionType: trueActionType,
        childNode: respData.trueChildNode,
        changeActionLoading: false
      }
      // 区分打分卡和预警规则
      if (self.Sketchpad.type === 'scorecard') {
        self.DecideContent.NodeWorkspaceTab.determinateTrueAction.classData = {
          scoreAdj: trueActionClassData
            ? parseInt(trueActionClassData.scoreAdj)
            : 0
        }
      } else{
        self.DecideContent.NodeWorkspaceTab.determinateTrueAction.classData = {
          eventSubject: trueActionClassData
            ? trueActionClassData.eventSubject
            : '',
          warningLevel: trueActionClassData
            ? trueActionClassData.warningLevel
            : 0
        }
      }

      self.DecideContent.NodeWorkspaceTab.determinateFalseAction = {
        oid: respData.rightNodeAction.oid,
        actionType: faleActionType,
        childNode: respData.falseChildNode,
        changeActionLoading: false
      }
      // 区分打分卡和预警规则
      if (self.Sketchpad.type === 'scorecard') {
        self.DecideContent.NodeWorkspaceTab.determinateFalseAction.classData = {
          scoreAdj: falseActionClassData
            ? parseInt(falseActionClassData.scoreAdj)
            : 0
        }
      } else{
        self.DecideContent.NodeWorkspaceTab.determinateFalseAction.classData = {
          eventSubject: falseActionClassData
            ? falseActionClassData.eventSubject
            : '',
          warningLevel: falseActionClassData
            ? falseActionClassData.warningLevel
            : 0
        }
      }

      // 如果左侧的数据源不为空，则重载工具栏数据
      if (self.DecideContent.NodeWorkspaceTab.choiseApi.fieldType) {
        self.loadToolList()
            }
    },
    // 保存判定工具
    saveTool() {
      const self = this
            // 获取当前选中的视图节点
            let choiseNodeOid = self.DecideContent.NodeMapTab.choiseNode.oid
            // 当前的选中的判定工具对象
            let determinaterTool = self.DecideContent.NodeWorkspaceTab.choiseTool

            // 获取当前工具的内容结构，如果内容为空，则获取默认内容结构
            let toolDeterminationData = JSON.parse(determinaterTool.determinationData + '')
            if (!toolDeterminationData) {
        toolDeterminationData = self.globalConst.DECIDE_TOOL_CONFIG[determinaterTool.code].determinationData
            }
      // 子组件数
      const childrenComponentList = self.$refs.ToolComponent.$children
            // 修改后的数据对象
            let changeData = {}

            // 工具内容中，所有的数据Key
            let toolDeterminationDataKeys = Object.keys(toolDeterminationData)
            // 根据内容结构的顺序，获取子组件的内容，并赋值
            toolDeterminationDataKeys.forEach(function(key, index) {
        // console.log(key,childrenComponentList[index].currentValue)
        changeData[key] = childrenComponentList[index].currentValue
            })
            
            //根据工具类型，回填determinationData
            //改变后的数据对象，但不知为何，不能进行JSON.stringify()，所以没进行赋值
            // console.log('changeData',changeData);
            // let test = {};
            // test['abc'] = 12345;
            // console.log(JSON.stringify(test));
            // console.log(JSON.stringify(changeData));
            let changeDataStr = JSON.stringify(changeData)
            determinaterTool.determinationData = changeDataStr
            // 设置按钮加载状态
            determinaterTool.changeToolLoading = true


            // 发送请求
            self.$http
        .patch(
          '/app/v1/sketchpads/detemineNodes/' + choiseNodeOid,
          {
            determinationData: changeDataStr
          }
        )
        .then(function(res) {
          determinaterTool.changeToolLoading = false
                    if (res.code === 0) {
            self.$Notice.success({
              title: '系统提示',
              desc: res.desc
            })
                    } else{
            self.$Notice.error({
              title: '系统提示',
              desc: res.desc
            })
                    }
        })
        },
    // 加载判定工具列表
    loadToolList() {
      const self = this
            let choiseApi = self.DecideContent.NodeWorkspaceTab.choiseApi

            // 先清空
            self.ToolNav.source = []

            // 发请求
            self.$http
        .get(
          '/app/v1/determinationTools/types/' +
                        choiseApi.fieldType
        )
        .then(function(res) {
          if (res.code === 0) {
            self.ToolNav.source = res.data
                    } else {
            self.$Notice.error({
              title: '系统提示',
              desc: res.desc
            })
                    }
        })
        }
  },
  created() {
    const self = this

        // 切换判定工具
        self.EventOperator.$on('rpcToolClick', function(tool) {
      const choiseTool = self.DecideContent.NodeWorkspaceTab.choiseTool
            
            if (choiseTool.oid !== tool.oid) {
        self.$Modal.confirm({
          title: '系统提示',
          content: '<p>确定选择判定工具“' + tool.name + '”？</p>',
          onOk: () => {
            const choiseNodeOid = self.DecideContent.NodeMapTab.choiseNode.oid
                        choiseTool.changeToolLoading = true
                        let determinationData = self.globalConst.DECIDE_TOOL_CONFIG[tool.code].determinationData

                        // 发送请求
                        self.$http
              .patch(
                '/app/v1/sketchpads/detemineNodes/' + choiseNodeOid,
                {
                  determinationToolOid: tool.oid,
                  determinationData: determinationData ? JSON.stringify(determinationData) : ''
                }
              )
              .then(function(res) {
                choiseTool.changeToolLoading = false
                                // console.log(res);
                                if (res.code === 0) {
                  self.DecideContent.NodeWorkspaceTab.choiseTool = {
                    oid: tool.oid,
                    name: tool.name,
                    code: tool.code,
                    determinationData: JSON.stringify(self.globalConst.DECIDE_TOOL_CONFIG[tool.code].determinationData)
                  }

                                    self.$Notice.success({
                    title: '系统提示',
                    desc: res.desc
                  })
                                }else {
                  self.$Notice.error({
                    title: '系统提示',
                    desc: res.desc
                  })
                                }
              })
                    },
          onCancel: () => {
            self.$Message.info('取消删除')
                    }
        }) 
            }
    })

        // 判定工具保存
        self.EventOperator.$on('rpcToolChange', function(newVal) {
      self.DecideContent.NodeWorkspaceTab.choiseTool.determinationData = newVal
        })

        // self.EventOperator.$on("rpcActionChange", function(change) {
        //     this[change.targe] = change.value;
        // });
    },
  mounted() {
    const self = this
        // 获取画板信息
        self.Sketchpad = {
      id: this.$route.query.pid,
      name: self.$route.query.pname,
      type: self.$route.query.type,
      isFullScreen: true
    }

        // 加载左侧的数据源列表
        self.loadApiCardList()

        // 加载和构建节点地图
        self.loadNodeMap().then(function(res) {
      if (res.code === 0) {
        self.DecideContent.NodeMapTab.source = res.data
                self.DecideContent.NodeMapTab.choiseNode = res.data[0]
                self.buildNodeMap()
            }else {
        self.$Notice.error({
          title: '系统提示',
          desc: res.desc
        })
            }
    })
    }
}
</script>
